﻿@using BBICMS.Infrastructure

@model BBICMS.Application.ViewModels.ProductListVM

@{
    ViewBag.Title = EntityNames.Product;
    ViewBag.PageTitle = ViewBag.Title + "_内容";

}

@section header{
    <style>
        .thumb{
            box-shadow:0 0 6px rgba(0,0,0,.15);
        }
    </style>


}

<div class="panel panel-default">
    <header class="panel-heading">
        <div class="text-right">
            <a class="btn btn-primary" href="@Url.Action("Add")"><i class="glyphicon glyphicon-plus"></i> @string.Format("{0}{1}", Buttons.Add, EntityNames.Product)</a>
     
        </div>
        <!--
        <form class="form-inline">
            <div class="form-group">
                <label for="BlogId">分类</label>
                @*@Html.DropDownListFor(model => model.BlogId, Model.Blogs, new { @class = "form-control" })*@
            </div>
            <div class="form-group">
                <label for="BlogId">关键字</label>
                @*@Html.TextBoxFor(model => model.Keyword, new { @class = "form-control" })*@
            </div>
            <button type="submit" class="btn btn-primary"><i class="fa fa-search fa-fw"></i>查找</button>
        </form>
            -->
    </header>


    <table class="table table-hover table-striped table-vmiddle">
        <thead>
            <tr>
                <th></th>
                <th>
                    主题
                </th>
                <th>
                    分类
                </th>

                <th>
                    查看
                </th>
                <th>
                    <span class="glyphicon glyphicon-time"></span> 创建日期
                </th>
                <th>
                    语言
                </th>
                <th>
                    推荐？
                </th>
                <th>
                    激活？
                </th>
                <th>
                    操作
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.ProductList)
            {
            <tr class="item-container">
                <td>
                    @if (!string.IsNullOrEmpty(item.Thumbnail))
        {
            <img src="@string.Format("{0}?width=40&height=40&mode=Width", item.Thumbnail)" class="thumb" />
}
                </td>

                <td>
                    @item.Title
                    @item.ProductNo
                </td>

                <td>
                    @item.CategoryTitle
                </td>

                <td>
                    @item.ViewCount
                </td>

                <td>@item.AddedDate.ToShortDateString()</td>
                <td>
                    <img src="@BBICMS.Repository.LanguageHelper.GetCultureIcon(item.Lang)" alt="@item.Lang" />
                </td>
                <td>
                    @if (item.Recommend)
        {
            <a href="#" data-url="@Url.Action("IsRecommend", new {id = item.Id})" class="recommend-item" title="推荐" data-action="撤消推荐">
                <i class="fa fa-check text-success"></i>
            </a>

}
else
{
            <a href="#" data-url="@Url.Action("IsRecommend", new {id = item.Id})" class="recommend-item" title="不推荐" data-action="推荐">
                <i class="fa fa-remove text-danger"></i>
            </a>
}
                </td>

                <td>
                    @if (item.Active)
        {
            <a href="#" data-url="@Url.Action("IsActive", new {id = item.Id})" class="active-item" title="激活" data-action="锁定">
                <i class="fa fa-check text-success"></i>
            </a>

}
else
{
            <a href="#" data-url="@Url.Action("IsActive", new {id = item.Id})" class="active-item" title="锁定" data-action="激活">
                <i class="fa fa-remove text-danger"></i>
            </a>
}
                </td>

                <td>
                    <a href="@Url.Action("Photos", new { productId = item.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-picture"></i></a>
                    <a href="@Url.Action("Edit", new { Id = item.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                    <a href="@Url.Action("Delete", new { Id = item.Id })" class="btn btn-xs btn-danger delete-item"><i class="glyphicon glyphicon-trash"></i></a>
                </td>
            </tr>
           }

        </tbody>

    </table>


    <footer class="panel-footer">
        <div class="row">
            <div class="col-sm-7">
                @Html.PagedListPager((IPagedList)Model.ProductList, page => Url.Action("Index", new { page}))
            </div>
            <div class="col-sm-5">
                <div class="text-right form-inline hidden">
                    总计 @Model.TotalCount 条，
                    分页：
                    @Html.DropDownListFor(model => model.PageSize, (SelectList)ViewBag.PageSizes, new { @class = "form-control" })
                </div>
            </div>
        </div>
    </footer>
</div>



<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>


@section footer{
    <script>
        $(function () {

            //锁定 激活
            //$('.active-item').click(function (e) {

            //    e.preventDefault();
            //    var url = $(this).attr('data-url'), title = $(this).attr('title'), that = $(this);
            //    Common.ActiveItem(url, title, that);

            //});

            $('.recommend-item,.active-item').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('data-url'), title = $(this).attr('data-action'), that = $(this);

                Common.SingleAction(url, title, that);

            });


            //删除数据
            $('.delete-item').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href'), that = $(this), title = '@string.Format("删除{0}", EntityNames.Category)';

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        Common.DeleteItem(url, title, that);
                    }
                });
            });



        });
    </script>
     
}
